<?php

namespace JLPay\Models\Trans\Dto;

/**
 * 商品明细DTO
 * 
 * @author liaochangyi
 * @since 2025-01-25
 */
class GoodsDetailDto
{
    protected ?string $goodsId = null;  // 商品编码
    protected ?string $wxpayGoodsId = null;  // 微信侧商品编码
    protected ?string $goodsName = null;  // 商品名称
    protected ?string $quantity = null;  // 商品数量
    protected ?string $price = null;  // 商品单价

    /**
     * 构造函数
     *
     * @param array|null $goodsDict 商品明细字典
     */
    public function __construct(?array $goodsDict = null)
    {
        if ($goodsDict) {
            $this->goodsId = $goodsDict['goods_id'] ?? null;
            $this->wxpayGoodsId = $goodsDict['wxpay_goods_id'] ?? null;
            $this->goodsName = $goodsDict['goods_name'] ?? null;
            $this->quantity = $goodsDict['quantity'] ?? null;
            $this->price = $goodsDict['price'] ?? null;
        }
    }

    /**
     * 获取商品编码
     *
     * @return string|null
     */
    public function getGoodsId(): ?string
    {
        return $this->goodsId;
    }

    /**
     * 设置商品编码
     *
     * @param string|null $goodsId
     * @return self
     */
    public function setGoodsId(?string $goodsId): self
    {
        $this->goodsId = $goodsId;
        return $this;
    }

    /**
     * 获取微信侧商品编码
     *
     * @return string|null
     */
    public function getWxpayGoodsId(): ?string
    {
        return $this->wxpayGoodsId;
    }

    /**
     * 设置微信侧商品编码
     *
     * @param string|null $wxpayGoodsId
     * @return self
     */
    public function setWxpayGoodsId(?string $wxpayGoodsId): self
    {
        $this->wxpayGoodsId = $wxpayGoodsId;
        return $this;
    }

    /**
     * 获取商品名称
     *
     * @return string|null
     */
    public function getGoodsName(): ?string
    {
        return $this->goodsName;
    }

    /**
     * 设置商品名称
     *
     * @param string|null $goodsName
     * @return self
     */
    public function setGoodsName(?string $goodsName): self
    {
        $this->goodsName = $goodsName;
        return $this;
    }

    /**
     * 获取商品数量
     *
     * @return string|null
     */
    public function getQuantity(): ?string
    {
        return $this->quantity;
    }

    /**
     * 设置商品数量
     *
     * @param string|null $quantity
     * @return self
     */
    public function setQuantity(?string $quantity): self
    {
        $this->quantity = $quantity;
        return $this;
    }

    /**
     * 获取商品单价
     *
     * @return string|null
     */
    public function getPrice(): ?string
    {
        return $this->price;
    }

    /**
     * 设置商品单价
     *
     * @param string|null $price
     * @return self
     */
    public function setPrice(?string $price): self
    {
        $this->price = $price;
        return $this;
    }

    /**
     * 转换为数组格式
     *
     * @return array
     */
    public function toArray(): array
    {
        return [
            'goods_id' => $this->goodsId,
            'wxpay_goods_id' => $this->wxpayGoodsId,
            'goods_name' => $this->goodsName,
            'quantity' => $this->quantity,
            'price' => $this->price
        ];
    }
} 